package com.hhxy.login.controller;

import com.hhxy.annotation.UserLoginToken;
import com.hhxy.login.service.misc.ApplicationService;
import com.hhxy.login.service.misc.ServiceChangeEvent;
import com.hhxy.login.utils.TokenUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

/**
 * @auther:Lu Yao
 * @date:2022/2/26
 **/
@Api(value="用户controller",tags={"登录接口"})
@RestController
public class Login {
    @Autowired(required = false)
    private RepositoryService repositoryService;
    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private final ApplicationService applicationService;

    public Login(ApplicationService applicationService) {
        this.applicationService = applicationService;
    }

   /* @Autowired(required = false)
    private IPersonService iPersonService;*/

/*
    @Autowired
    private UserService userService;
*/

    @ApiOperation(value="登录",tags={"登录"})
    @GetMapping("/login")
    public String login( @PathVariable("id") String id){
        //String forObject = restTemplate.getForObject("http://localhost:8081/upload", String.class);
        /*List<User> list = userService.list();
        User byId = userService.getById(id);
        String s = JSON.toJSONString(byId);*/
        applicationService.pushEvent(new ServiceChangeEvent("1"));
        String s="";
        return s;
    }

   /* @ApiOperation(value="验证",tags={"验证"})
    @GetMapping("/certify/{name}")
    public String getPerson(@PathVariable("name") String name){
        //String forObject = restTemplate.getForObject("http://localhost:8081/upload", String.class);
        Person byId = iPersonService.getById(name);
        String s = JSON.toJSONString(byId);
        return s;
    }
    @ApiOperation(value="验证",tags={"验证"})
    @GetMapping("/num")
    public int getCount(){
        //String forObject = restTemplate.getForObject("h@ttp://localhost:8081/upload", String.class);
        int a = iPersonService.count();
        return a;
    }*/
    /***
     * 这个请求需要验证token才能访问
     *
     * @author: qiaoyn
     * @date 2019/06/14
     * @return String 返回类型
     */
    @UserLoginToken
    @ApiOperation(value = "获取信息", notes = "获取信息")
    @RequestMapping(value = "/getMessage" ,method = RequestMethod.GET)
    public String getMessage() {

        // 取出token中带的用户id 进行操作
        System.out.println(TokenUtil.getTokenUserId());

        return "您已通过验证";
    }
    @GetMapping("/test")
    public void test(String[] args) {
        Deployment deployment = repositoryService.createDeployment().name("测试流程文件部署")
                .addClasspathResource("processes/myTask.xml")
                .deploy();

        System.out.println("部署id为："+deployment.getId());
        System.out.println("部署名称为："+deployment.getName());
    }

}